<template>
  <view class="pwd-retrieve-container">
    <uni-forms ref="form" label-position="top" :value="user" labelWidth="200px">
      <uni-forms-item name="newPassword" label="设置新密码">
        <input
          v-model="user.newPassword"
          type="number"
          class="input"
          placeholder="请设置新密码"
        />
      </uni-forms-item>
      <uni-forms-item name="confirmPassword" label="请再次输入新密码">
        <input
          v-model="user.confirmPassword"
          type="number"
          class="input"
          placeholder="请再次输入新密码"
        />
      </uni-forms-item>
      <button type="primary" class="lg round" @click="submit">提交</button>
    </uni-forms>
  </view>
</template>

<script>
export default {
  data() {
    return {
      user: {
        newPassword: undefined,
        confirmPassword: undefined,
      },
      rules: {
        newPassword: {
          rules: [
            {
              required: true,
              errorMessage: "新密码不能为空",
            },
            {
              minLength: 6,
              maxLength: 20,
              errorMessage: "长度在 6 到 20 个字符",
            },
          ],
        },
        confirmPassword: {
          rules: [
            {
              required: true,
              errorMessage: "确认密码不能为空",
            },
            {
              validateFunction: (rule, value, data) =>
                data.newPassword === value,
              errorMessage: "两次输入的密码不一致",
            },
          ],
        },
      },
    };
  },
  onReady() {
    this.$refs.form.setRules(this.rules);
  },
  methods: {
    submit() {
      this.$refs.form.validate().then((res) => {
        // updateUserPwd(this.user.newPassword).then((response) => {
        this.$modal.msgSuccess("修改成功");
        // });
      });
    },
  },
};
</script>

<style lang="scss">
page {
  background-color: #ffffff;
}

.pwd-retrieve-container {
  padding-top: 36rpx;
  padding: 15px;
  .uni-forms-item {
    border-bottom: 1px solid #eee;
    padding-bottom: 20upx;
  }
  /deep/ .uni-forms-item__label {
    font-weight: 700;
    font-size: 34upx;
    color: #333333;
  }
  .pswInput {
    border: 0;
  }
}
</style>
